home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CFonts.h
-
- Contains: Font manager wrapper classes
-
- Written by: Arno Gourdol
-
- Copyright: © 1994-1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
-
- */
-
- #pragma once
-
- #ifndef __CFONTS__
- #define __CFONTS__
-
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Script.h>
- #include <TextEdit.h>
- #include <TextUtils.h>
-
- #include "CRect.h"
-
- enum
- {
- smNoScript = -10 // Invalid script code
- };
-
- typedef enum FontCode
- {
- kMonospacedFont = smScriptMonoFondSize, // Default mono-spaced font (Monaco 9)
- kPreferedFont = smScriptPrefFondSize, // Prefered font for the script
- kSmallFont = smScriptSmallFondSize, // Default small font (Geneva 9)
- kSystemFont = smScriptSysFondSize, // Designate the system font (Chicago 12 for Roman systems)
- kApplicationFont = smScriptAppFondSize, // Default application font
- kHelpManagerFont = smScriptHelpFondSize // Default font used by the Help Manager for Balloon help
- } FontCode;
-
-
-
-
- // Cache for the international resources for the system script
- extern Handle gItl0;
- extern Handle gItl2;
-
-
- class CFontSpec
- {
- public:
- // constructors
- CFontSpec(void);
- CFontSpec(ScriptCode scriptCode,
- FontCode font);
-
- // destructor
- ~CFontSpec(void);
-
- // mutators
- void SetFont(ScriptCode scriptCode,
- FontCode font = kSystemFont);
- Boolean SetFont(ScriptCode scriptCode,
- ConstStr255Param fontName);
- void SetFontID(short font);
- void SetSize(short size);
- void SetStyle(short style);
- void SetMode(short mode);
-
- // accessors
- inline Boolean IsLeftToRight(void) const;
- inline Boolean IsRightToLeft(void) const;
- inline ScriptCode GetScriptCode(void) const;
- inline void GetFont(Str255& fontName) const;
- inline short GetFont(void) const;
- inline short GetSize(void) const;
- inline short GetStyle(void) const;
- inline short GetMode(void) const;
- void GetFontMetrics(short& lineHeight,
- short& ascent,
- short& descent);
- inline UInt16 GetLineHeight(void);
-
- // string manipulation
- void TruncString(short width,
- Str255 string,
- TruncCode where = smTruncMiddle);
- short MeasureString(ConstStr255Param string) const;
- void DrawString(ConstStr255Param string) const;
- void DrawText(ConstStr255Param string,
- const CRect& bounds,
- short align = teFlushDefault) const;
- TEHandle TENew(void) const;
- void SetPortFont(GrafPtr port) const;
-
- static const CFontSpec& GetSystemFontSpec(void);
- static const CFontSpec& GetSmallFontSpec(void);
- static Handle GetIntlResource(short id);
-
- // Object state changes
- void Save(void);
- void Restore(void);
- void Use(void) const;
- private:
-
- // Caches
- ScriptCode FontToScript(short font);
- Boolean SupportCondense(ScriptCode script);
- Boolean ScriptIsRTL(ScriptCode script);
- long ScriptFont(ScriptCode script, short font);
-
- ScriptCode fScript; // Script of the font
- short fFont; // Font ID
- short fSize; // Font size
- short fStyle; // Font style (bold, italic, etc...)
- short fMode; // Font mode
-
- short fLineHeight; // Height of a line of text
- short fAscent; // Ascent of a line of text
- short fDescent; // Descent of a line of text
- Boolean fRightToLeft; // True if the font is a right-to-left font
-
- // Cached information
- // Item on first line is input, second line is output
- static short fFontToScriptCacheFont;
- static ScriptCode fFontToScriptCacheScript;
-
- static ScriptCode fSupportsCondenseCacheScript;
- static Boolean fSupportsCondenseCache;
-
- static ScriptCode fScriptIsRTLCacheScript;
- static Boolean fScriptIsRTLCache; // True if rtl
-
- static ScriptCode fScriptFontCacheScript;
- static short fScriptFontCacheFont;
- static long fScriptFontCacheFontAndSize;
-
- static Boolean pSystemFontInited;
- // static CFontSpec pSystemFontSpec;
-
- static Boolean pSmallFontInited;
- // static CFontSpec pSmallFontSpec;
-
- static Handle pItl0;
- static Handle pItl1;
- static Handle pItl2;
-
- static Handle FetchIntlResource(short id);
-
- #ifndef NDEBUG
- short fSaveCount; // Number of times Save() has been called
- #endif
-
- };
-
-
-
- //
- // CFontSpec inlines
- //
- //
-
- inline Boolean CFontSpec::IsLeftToRight(void) const
- {
- return !fRightToLeft;
- }
-
- inline Boolean CFontSpec::IsRightToLeft(void) const
- {
- return fRightToLeft;
- }
-
- inline ScriptCode CFontSpec::GetScriptCode(void) const
- {
- return fScript;
- }
-
- inline void CFontSpec::GetFont(Str255& fontName) const
- {
- ::GetFontName(fFont, fontName);
- }
-
- inline short CFontSpec::GetFont(void) const
- {
- return fFont;
- }
-
- inline short CFontSpec::GetSize(void) const
- {
- return fSize;
- }
-
-
- inline short CFontSpec::GetStyle(void) const
- {
- return fStyle;
- }
-
-
- inline short CFontSpec::GetMode(void) const
- {
- return fMode;
- }
-
- inline UInt16 CFontSpec::GetLineHeight(void)
- {
- UInt16 lineHeight;
- UInt16 ascent;
- UInt16 descent;
-
- GetFontMetrics(lineHeight, ascent, descent);
-
- return lineHeight;
- }
-
-
- #endif